local hx__miaosuan = fk.CreateSkill {
  name = "hx__miaosuan",
  tags = { Skill.Compulsory },
}

hx__miaosuan:addEffect(fk.AfterSkillEffect, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(hx__miaosuan.name) and player.maxHp ~= 13 and player:usedEffectTimes(hx__miaosuan.name) < 20 then
      return (player:getMark("@hx__renxin") > 0 and player:getMark("@hx__renxin") % 2 == 0)
      or (player:getMark("hx__chengxiang13") > 0)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player.maxHp - player.hp - 3
    local choices = {"hx__miaosuan_maxhp"}
    if x > 0 then
      table.insert(choices, "hx__miaosuan_draw")
    end
    if player:getMark("hx__chengxiang13") > 0 then
      local choice = room:askToChoice(player,{
        choices = choices,
        skill_name = hx__miaosuan.name,
      })
      if choice == "hx__miaosuan_maxhp" then
        room:changeMaxHp(player, 1)
      elseif choice == "hx__miaosuan_draw" then
        room:drawCards(player, x, hx__miaosuan.name)
      end
      room:setPlayerMark(player,"hx__chengxiang13", 0)
    else
      local choice = room:askToChoice(player,{
        choices = choices,
        skill_name = hx__miaosuan.name,
      })
      if choice == "hx__miaosuan_maxhp" then
        room:changeMaxHp(player, 1)
      elseif choice == "hx__miaosuan_draw" then
        room:drawCards(player, x, hx__miaosuan.name)
      end
      room:setPlayerMark(player,"@hx__renxin", 0)
    end
  end,
})

return hx__miaosuan
